package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author:ahang
 * @create:2022-09-28 20:02
 * @Description:
 */
@RequestMapping("admin/product/")
@RestController
public class TrademarkController {

    @Autowired
    private BaseTrademarkService baseTrademarkService;

    /**
     * 获取品牌分页列表
     * @param pn
     * @param ln
     * @return
     */
    @GetMapping("baseTrademark/{page}/{limit}")
    public Result getTrademarkList(@PathVariable("page") Long pn,@PathVariable("limit") Long ln){

        Page<BaseTrademark> page = new Page<>(pn,ln);
        Page<BaseTrademark> result = baseTrademarkService.page(page);
        return Result.ok(result);
    }

    /**
     * 添加品牌
     * @return
     */
    @PostMapping("baseTrademark/save")
    public Result saveTrademark(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    /**
     * 删除品牌
     * @return
     */
    @DeleteMapping("baseTrademark/remove/{id}")
    public Result deleteTrademark(@PathVariable("id") Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    /**
     * 根据id获取品牌
     * @return
     */
    @GetMapping("baseTrademark/get/{id}")
    public Result getTrademark(@PathVariable("id") Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    /**
     * 修改品牌
     * @param baseTrademark
     * @return
     */
    @PutMapping("baseTrademark/update")
    public Result updateTrademark(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    /**
     * 获取所有的品牌信息
     * @return
     */
    @GetMapping("baseTrademark/getTrademarkList")
    public Result getAllTrademark(){
        List<BaseTrademark> list = baseTrademarkService.list();
        return Result.ok(list);
    }

}
